'''
Created on 2011/03/10

@author: Administrator
'''
import datetime
from util.models import RecentEvaluation

class RecentEvaluationClass():
    def __init__(self):
        self.EVALUATION_MAX=5

    def updatePlayersEvaluations(self,playersEvaluations):

        
        for playerID in playersEvaluations:
            recentEvaluations = playersEvaluations[playerID]
            newEvaluationSize = len(recentEvaluations)
            deleteModels = RecentEvaluation.gql('WHERE evaluatedID = :1 ORDER BY evaluateTime',playerID)
            i=0
            for deleteModel in deleteModels:
                i+=1
                if i>(self.EVALUATION_MAX-newEvaluationSize):
                    deleteModel.delete()
                       
            
            for re in recentEvaluations:
                newReModel = RecentEvaluation(evaluaterID=re['evaluaterID'], evaluatedID=playerID, evaluateTime=datetime.date.today(), fieldID=re['fieldID'], fieldTitle=re['fieldTitle'],rank=re['rank'],noCountFlag=0)
                newReModel.put()
            
        
    def getRecentEvaluations(self,playerID):
        recentEvaluations = RecentEvaluation.gql('WHERE evaluatedID = :1 ORDER BY evaluateTime DESC', playerID) 
        return recentEvaluations
 